package com.cjz.rxjavalearn;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.widget.TextView;

import com.cjz.rxjavalearn.api.API;
import com.cjz.rxjavalearn.pojo.DailyWeatherData;
import com.cjz.rxjavalearn.pojo.Top250MovieData;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends Activity {

    private TextView tvDailyData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        tvDailyData = (TextView) findViewById(R.id.tvDailyData);
        tvDailyData.setMovementMethod(new ScrollingMovementMethod());


        tvDailyData.setOnClickListener(view -> {
            getWeatherData();
        });

    }

    private void getWeatherData() {

//        RetrofitDemoApp.getApp()
//                .getRetrofit()
//                .create(API.GetWeatherDaily.class)
//                .getDataFromNet("coyb6sbdq3a751sp", "beijing", "zh-Hans", "c", 0, 5)
//                .enqueue(new Callback<DailyWeatherData>() {
//                    @Override
//                    public void onResponse(Call<DailyWeatherData> call, Response<DailyWeatherData> response) {
//                        DailyWeatherData data = response.body();
//                        tvDailyData.setText(data.toString());
//                    }
//
//                    @Override
//                    public void onFailure(Call<DailyWeatherData> call, Throwable t) {
//
//                    }
//                })
//        ;


        RetrofitDemoApp.getApp()
                .getRetrofit()
                .create(API.GetMoviesAPI.class)
                .getMovies("v2", 0, 20)
                .enqueue(new Callback<Top250MovieData>() {
                    @Override
                    public void onResponse(Call<Top250MovieData> call, Response<Top250MovieData> response) {
                        if(response.isSuccessful()){
                            Top250MovieData data = response.body();

                            //T0D0 ...bulabula...

                            tvDailyData.setText(data.toString());
                        }
                    }

                    @Override
                    public void onFailure(Call<Top250MovieData> call, Throwable t) {

                    }
                });

    }

}
